 // Image.cpp: implementation of the Image class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "sift.h"
#include "Image.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Image::Image()
{
	height=0;
	width=0;
	scale=0;
}

Image::~Image()
{
	/*if (this->pic!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->pic[i]);
		free(this->pic);
	}
	if (this->mag!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->mag[i]);
		free(this->mag);
	}
	if (this->ori!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->ori[i]);
		free(this->ori);
	}*/

	/*if (this->pic!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete []this->pic[i];
		delete [] (this->pic);
	}
	if (this->mag!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete [] (this->mag[i]);
		delete [] (this->mag);
	}
	if (this->ori!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete [] (this->ori[i]);
		delete [] (this->ori);
	}*/
}

void Image::allocateImage()
{
	this->pic=(double  **)malloc(this->height*sizeof(double *));
	if (this->pic==NULL)
	{
		return ;
	}
	this->mag=(double  **)malloc(this->height*sizeof(double *));
	if (this->mag==NULL)
	{
		return;
	}
	this->ori=(double  **)malloc(this->height*sizeof(double *));
	if (this->ori==NULL)
	{
		return ;
	}
	for(int i=0;i<this->height;i++)
	{
		this->pic[i]=(double *)malloc(this->width*sizeof(double));
		this->mag[i]=(double *)malloc(this->width*sizeof(double));
		this->ori[i]=(double *)malloc(this->width*sizeof(double));
	}

/*	this->pic=new double*[this->height];
	this->mag=new double*[this->height];
	this->ori=new double*[this->height];
	for(int i=0;i<this->height;i++)
	{
		this->pic[i]=new double[this->width];
		this->mag[i]=new double[this->width];
		this->ori[i]=new double[this->width];
	}*/
}
void Image::freeImage()
{
	if (this->pic!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->pic[i]);
		free(this->pic);
	}
	if (this->mag!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->mag[i]);
		free(this->mag);
	}
	if (this->ori!=NULL)
	{
		for(int i=0;i<this->height;i++)
			free(this->ori[i]);
		free(this->ori);
	}



/*	if (this->pic!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete []this->pic[i];
		delete [] (this->pic);
	}
	if (this->mag!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete [] (this->mag[i]);
		delete [] (this->mag);
	}
	if (this->ori!=NULL)
	{
		for(int i=0;i<this->height;i++)
			delete [] (this->ori[i]);
		delete [] (this->ori);
	}*/
}